import { EnumBoutState } from "../modules/BoutModule"
import RobotModel from "./RobotModel"

@Component
export default class GameModel extends mw.Script {
    private static _instance: GameModel
    static get instance(): GameModel { return this._instance }

    onBoutStateChangedEvent:Action = new Action()
    onFightingBeginTimeChanged:Action = new Action()
    onBoutFightCharacterArrayChanged:Action = new Action()
    onLessenCircleTimeChanged:Action = new Action()
    
    // 参加对局的人
    @mw.Property({ multicast: true, replicated: true, onChanged:'onFightingCharacterChanged' })
    fightingCharacter:number[] = []
    // 参加对局的人
    @mw.Property({ multicast: true, replicated: true, onChanged:'onBoutStateChanged' })
    boutState:EnumBoutState
    // 下次缩圈倒计时
    @mw.Property({ multicast: true, replicated: true, onChanged:'lessenCircleTimeChanged' })
    nextLessenCircleTime:number = 0
    // 比赛开始倒计时
    @mw.Property({ multicast: true, replicated: true, onChanged:'fightingBeginTimeChanged' })
    fightingBeginTime:number = 0

    playerStartPosition:Vector

    protected onStart(): void {
        GameModel._instance = this
        this.playerStartPosition = GameObject.findGameObjectById('DC5A4E2B47A0C6E31572FE9882BE6861').worldTransform.position
    }

    getCharacterBySceneID(sceneID:number):Character|undefined{
        if(RobotModel.isRobot(sceneID)) {
            return RobotModel.robotMap.get(sceneID)?.character
        }
        return Player.getPlayer(sceneID)?.character
    }

    private onFightingCharacterChanged(){
        this.onBoutFightCharacterArrayChanged.call()
    }

    private onBoutStateChanged(){
        this.onBoutStateChangedEvent.call()
    }

    private fightingBeginTimeChanged(){
        this.onFightingBeginTimeChanged.call()
    }

    private lessenCircleTimeChanged(){
        this.onLessenCircleTimeChanged.call()
    }
}